Skip to content

fix(toolsets): add accountIds option to StackOneToolSetConfig#252

Merged
glebedel merged 8 commits intomainfrom
feat/multi-account-initialisation
Dec 16, 2025
Merged

fix(toolsets): add accountIds option to StackOneToolSetConfig#252
glebedel merged 8 commits intomainfrom
feat/multi-account-initialisation

Conversation

@ryoppippi
Copy link
Copy Markdown
Contributor

@ryoppippi ryoppippi commented Dec 16, 2025

Summary

  • Add accountIds option to StackOneToolSetConfig for passing multiple accounts during class initialisation
  • Use type-fest's MergeExclusive to enforce mutual exclusivity between accountId and accountIds at compile time
  • Add runtime validation that throws ToolSetConfigError when both options are provided (protects JavaScript users)
  • Add comprehensive type-level tests using vitest's expectTypeOf

This enables a more ergonomic API with type safety:

// Valid: single account
new StackOneToolSet({ accountId: 'acc1' });

// Valid: multiple accounts
new StackOneToolSet({ accountIds: ['acc1', 'acc2', 'acc3'] });

// TypeScript error + runtime error: cannot use both
new StackOneToolSet({ accountId: 'acc1', accountIds: ['acc2'] });
// => ToolSetConfigError: Cannot provide both accountId and accountIds...

Closes #251

Test plan

  • Unit tests for initialising with accountId alone
  • Unit tests for initialising with accountIds alone
  • Unit tests for default empty array when neither provided
  • Runtime validation test - throws ToolSetConfigError when both provided
  • Type-level tests using expectTypeOf().toExtend() for valid configs
  • Type-level tests using expectTypeOf().not.toExtend() for invalid config (both options)
  • Integration tests for fetchTools using constructor accountIds
  • Integration tests verifying setAccounts() overrides constructor accountIds
  • All existing tests pass (335 tests)
  • Linter passes

Allow passing multiple account IDs when initialising StackOneToolSet
via the constructor, eliminating the need to call setAccounts()
separately after instantiation.

- Add accountIds property to StackOneToolSetConfig interface with
  JSDoc documentation
- Initialise accountIds from config in constructor
- Update constructor JSDoc to reflect support for multiple account IDs

This change enables a more ergonomic API for multi-account setups:

```typescript
const toolset = new StackOneToolSet({
  apiKey: 'key',
  accountIds: ['acc1', 'acc2', 'acc3'],
});
```

Closes #251
Add comprehensive tests verifying the new accountIds configuration:

- Test initialising with multiple account IDs from constructor
- Test default empty array when accountIds not provided
- Test coexistence of accountId and accountIds in constructor
- Test fetchTools uses constructor accountIds when present
- Test setAccounts() overrides constructor accountIds

These tests ensure accountIds from the constructor integrates
correctly with existing setAccounts() and fetchTools() behaviours.
@ryoppippi ryoppippi requested a review from a team as a code owner December 16, 2025 14:31
Copilot AI review requested due to automatic review settings December 16, 2025 14:31
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Dec 16, 2025

Open in StackBlitz

npm i https://pkg.pr.new/StackOneHQ/stackone-ai-node/@stackone/ai@252

commit: 9b614e2

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a convenient accountIds option to the StackOneToolSetConfig interface, enabling single-step initialization of a toolset with multiple account IDs. Previously, users needed to instantiate the toolset and then call setAccounts() separately. This change maintains full backward compatibility with existing code while providing a more ergonomic API.

Key Changes

  • Added accountIds array property to StackOneToolSetConfig interface with comprehensive JSDoc
  • Constructor now initializes this.accountIds from config, defaulting to empty array
  • Updated constructor JSDoc to reference "account ID(s)" plural form

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/toolsets.ts Adds accountIds optional property to config interface with JSDoc and initializes it in constructor (line 185)
src/toolsets.test.ts Comprehensive test coverage including constructor initialization, default values, coexistence with accountId, and interaction with setAccounts() method

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +97 to +98
* Array of account IDs for filtering tools across multiple accounts
* When provided, tools will be fetched for all specified accounts
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JSDoc states "When provided, tools will be fetched for all specified accounts" but this is imprecise. The accountIds are stored during construction, but tools are only fetched when fetchTools() is called later. Consider rephrasing to something like "When provided, these account IDs will be used when fetching tools" or "Array of account IDs to use for filtering tools during fetchTools() calls".

Suggested change
* Array of account IDs for filtering tools across multiple accounts
* When provided, tools will be fetched for all specified accounts
* Array of account IDs to use for filtering tools during fetchTools() calls.
* Only tools available on these accounts will be returned when fetchTools() is called.

Copilot uses AI. Check for mistakes.
… options

Use type-fest's MergeExclusive to enforce that either accountId (single)
or accountIds (multiple) can be provided, but not both simultaneously.

This improves type safety by catching invalid configurations at compile
time rather than runtime. The API now clearly communicates the intended
usage pattern through the type system.

Before (both allowed - confusing behaviour):
```typescript
new StackOneToolSet({
  accountId: 'acc1',
  accountIds: ['acc2', 'acc3'],  // Which takes precedence?
});
```

After (type error - clear contract):
```typescript
// Valid: single account
new StackOneToolSet({ accountId: 'acc1' });

// Valid: multiple accounts
new StackOneToolSet({ accountIds: ['acc1', 'acc2'] });

// Type error: cannot use both
new StackOneToolSet({ accountId: 'acc1', accountIds: ['acc2'] });
```
Update test to verify that the type system enforces mutual exclusivity
between accountId and accountIds. Replace the test that allowed both
with a new test demonstrating the correct API usage patterns.

- Test single accountId configuration works correctly
- Test multiple accountIds configuration works correctly
- Document that combining both is a type error (prevented at compile time)
Add comprehensive type tests using vitest's expectTypeOf to verify
the MergeExclusive behaviour of account configuration options:

- Test that accountId alone is valid
- Test that accountIds alone is valid
- Test that neither is valid (optional)
- Test that both together is rejected by the type system
- Verify accountId is typed as string | undefined
- Verify accountIds is typed as string[] | undefined
@ryoppippi ryoppippi force-pushed the feat/multi-account-initialisation branch from e6fbcc6 to cac507c Compare December 16, 2025 14:44
… options

Add runtime check to throw ToolSetConfigError when both accountId and
accountIds are provided simultaneously. This protects JavaScript users
and scenarios where TypeScript is bypassed (e.g., using 'as any').

The validation uses != null to check for both null and undefined in a
single comparison, ensuring the error is thrown regardless of how the
invalid configuration is constructed.
…counts

Add test to verify ToolSetConfigError is thrown when both accountId and
accountIds are provided at runtime. Uses 'as never' to bypass TypeScript
type checking and simulate JavaScript usage scenarios.
@ryoppippi ryoppippi changed the title feat(toolsets): add accountIds option to StackOneToolSetConfig fix(toolsets): add accountIds option to StackOneToolSetConfig Dec 16, 2025
Copy link
Copy Markdown
Contributor

@glebedel glebedel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@glebedel glebedel merged commit 33973ed into main Dec 16, 2025
11 checks passed
@glebedel glebedel deleted the feat/multi-account-initialisation branch December 16, 2025 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pass multiple accounts for initialising class

3 participants